<script setup>

//定义的各种数据
import {reactive, ref} from "vue";
import xx from "@/axios/xx";
import {ElMessage, genFileId} from "element-plus";
import {Delete, Download, Edit, Plus, Search, Upload} from "@element-plus/icons-vue";

let info = reactive({
  list:[],//列表数据
  form:{},//表单数据
  dialogVisible:false,//对话框数据
  pageNum: 1, //当前页
  pageSize: 5, //每页大小
  total: 0,//总条数
  loanTypeList:[],//分类信息所有数据
  bankList:[],//银行所有数据
  userInfoList:[],
  loanApplicationList:[],
})


//查询列表信息
const load = () => {
  xx.get('/repaymentMonitoring/listToAdm',{
    params:{
      pageNum:info.pageNum,
      pageSize:info.pageSize,
      overdueStatus:info.form.overStatus,
      processingStatus:info.form.processingStatus,
    }
  }).then(res =>{
    console.log(res)
    info.list = res.data.list
    //当前页
    info.pageNum = res.data.pageNum;
    //每页大小
    info.pageSize = res.data.pageSize;
    //总条数
    info.total = res.data.total;


  })
}

load()

//分页当前页改变
const handleCurrentChange = (pageNum) => {
  info.pageNum = pageNum;
  load()
}

//分页大小改变
const handleSizeChange = (pageSize) => {
  info.pageSize = pageSize;
  load()
}


//关闭对话框，清空数据
const handleClose = () => {
  info.form = {}
  info.dialogVisible = false
}


//持久化数据
const persistence = () => {
  xx({
    url:'/repaymentMonitoring',
    method:'put',
    data:info.form
  }).then(res => {
    if (res.code === 200) {
      ElMessage({
        message: res.message,
        type: 'success',
      })
    } else {
      ElMessage.error(res.message)
    }
    //关闭对话框
    info.dialogVisible = false
    info.form = {} //情况数据
    load()
  })
}
//点击修改按钮  - 根据id查询对应的数据
const handleEdit = (id) => {
  xx.get('repaymentMonitoring/'+id).then(res => {
    console.log(res)
    info.form = res.data
  })
  info.dialogVisible = true
}

//删除
const handleDelete = (id) => {
  xx.delete('/repaymentMonitoring/'+id).then(res => {
    console.log(res)
    if(res.code === 200){
      ElMessage({
        message: res.message,
        type:'success',
      })
    }else {
      ElMessage.error(res.message)
    }
    load()
  })
}

</script>

<template>
  <div class="applicationStatus">
    <br>
    <!--快捷查询-->
    <el-form :inline="true" :model="info.form" class="demo-form-inline">
      <el-form-item label="逾期情况：">
        <el-input label="逾期情况" v-model="info.form.overStatus"  placeholder="精准查询" clearable >
        </el-input>
      </el-form-item>
      <el-form-item label="处理状态：">
        <el-input label="处理状态" v-model="info.form.processingStatus"  placeholder="精准查询" clearable >
        </el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="load" :icon="Search">查询</el-button>
      </el-form-item>
    </el-form>
    <!--表格信息-->
    <el-table :data="info.list" border stripe style="width: 100%">
      <el-table-column fixed type="index" align="center" label="序号" width="80" />
      <el-table-column fixed prop="loanApplication.userInfo.username" align="center" label="贷款申请账号" width="180" />
      <el-table-column fixed prop="loanApplication.userInfo.creditRank" align="center" label="信用等级" width="100" />
      <el-table-column fixed prop="repaymentAmount" align="center" label="已还款金额(￥)" width="100" />
      <el-table-column fixed prop="loanApplication.loanType.money" align="center" label="贷款金额(￥)" width="100" />
      <el-table-column fixed prop="loanApplication.startDate" align="center" label="贷款日期" width="150" />
      <el-table-column fixed prop="loanApplication.deadline" align="center" label="还款日期" width="150" />
      <el-table-column prop="loanApplication.loanType.loanTypeName" align="center" label="贷款类型名称" width="120" />
      <el-table-column prop="loanApplication.loanType.description" align="center"label="描述信息" />
      <el-table-column fixed="right" prop="overdueStatus" align="center" label="逾期状态" width="100"  />
      <el-table-column fixed="right" prop="processingStatus" align="center" label="审核状态" width="100"  />
      <el-table-column fixed="right" align="center" label="操作" width="200" >
        <template #default="scope">
<!--          <el-button size="small" style="background-color: bisque" @click="handleEdit(scope.row.id)"><el-icon class="el-icon&#45;&#45;left" ><Edit /></el-icon>
            降级 </el-button>-->
          <el-button size="small" v-if="scope.row.processingStatus==='未处理'" style="background-color: bisque" @click="handleEdit(scope.row.id)"><el-icon class="el-icon--left" ><Edit /></el-icon>
            修改 </el-button>
          <el-popconfirm @confirm="handleDelete(scope.row.id)" title="你确定要删除吗?">
            <template #reference>
              <el-button size="small" type="danger" ><el-icon class="el-icon--left" ><Delete /></el-icon>
                删除 </el-button>
            </template>
          </el-popconfirm>
        </template>
      </el-table-column>
    </el-table>
    <!--分页-->
    <br>
    <div class="demonstration"></div>
    <el-pagination
        v-model:current-page="info.pageNum"
        v-model:page-size="info.pageSize"
        :page-sizes="[5, 10, 15, 20]"
        :small="false"
        :disabled="false"
        :background="true"
        layout="total, sizes, prev, pager, next, jumper"
        :total="info.total"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
    />
  </div>

  <!--修改监测数据对话框窗口-->
  <el-dialog
      v-model="info.dialogVisible"
      title="修改监测数据"
      width="40%"
      :before-close="handleClose"
  >
    <el-form :model="info.form" label-width="auto" style="max-width: 90%;margin-left: 20px">
      <el-form-item label="已还款金额" style="margin-left: 30px" >
        <el-input v-model="info.form.repaymentAmount"/>
      </el-form-item>
      <el-form-item label="逾期情况" style="margin-left: 30px" >
        <el-input v-model="info.form.overdueStatus"  />
      </el-form-item>
      <el-form-item label="处理状态" style="margin-left: 30px">
        <el-input v-model="info.form.processingStatus"  />
      </el-form-item>
    </el-form>
    <template #footer>
      <div class="dialog-footer">
        <el-button type="primary" @click="persistence" > 保存信息 </el-button>
      </div>
    </template>
  </el-dialog>

</template>

<style scoped>

</style>